<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1" charset="utf-8">
    <link rel="stylesheet" href="../javascripts/lib/jqm/jquery.mobile-1.4.3.min.css"/>
      <!--<link rel="stylesheet" href="../stylesheets/jscrollpane1.css"/>-->
    <link rel="stylesheet" href="../stylesheets/main.css"/>
    <script src="../javascripts/lib/jq/jquery-2.1.1.min.js"></script>
    <script src="../javascripts/lib/jqm/jquery.mobile-1.4.3.min.js"></script>
      <script type="text/javascript">
          $(function() {
              $( ".selector" ).page({ domCache: false });
          })

      </script>
    <title><%=title%></title>
  </head>
  <body>
    <div class="a" data-role="page" id="msgListPage" data-dom-cache="false">
      <div data-role="header" id="header">
          <!--<a class="ui-btn ui-btn-inline ui-icon-delete ui-btn-icon-left" id="wcback" href="#">关闭</a>-->
          <a class="ui-btn-left ui-btn ui-btn-inline ui-mini ui-corner-all ui-btn-icon-left ui-icon-delete" id="wcback" href="#">关闭</a>
          <h1>历史记录</h1>
         <!-- <a class="ui-btn ui-corner-all ui-btn-inline ui-mini footer-button-right ui-btn-icon-right ui-icon-carat-r" data-transition="slide" href="/wcpay/orderlist?openid=<%=openid%>">服务记录</a>
     --> </div>
      <div data-role="content" data-theme="c" >
          <script type="text/javascript">
              /*var totalheight = 0;     //定义一个总的高度变量
              function loaata()
              {alert('sssssssss');
                  totalheight = parseFloat($(window).height()) + parseFloat($(window).scrollTop());     //浏览器的高度加上滚动条的高度
                    //alert(totalheight+" "+$(document).height());
                  if ($(document).height() <= totalheight)     //当文档的高度小于或者等于总的高度的时候，开始动态加载数据
                  {
                      //加载数据
                      var content = "<li><a href=\"#\">这是加载的数据</a></li>";
                      $("#listview").append(content).listview('refresh');

                  }
              }*/


              /*$(function() {

              });*/
//              function loadData(){
                  /*var content = "<li><a href=\"#\">这是加载的数据</a></li>";
                  $("#listview").append(content).listview('refresh');*/

//              }
              $("#wcback").click(function(){
                  WeixinJSBridge.call('closeWindow');//微信内置浏览器关闭当前页面
                  countref = 0;//防止关闭时不必要的刷新listview
              });

              $(function(){
                  var snum =0;
                  $("#btnMore").click(function() {
                      //alert('sssssssss');
                      snum+=3;
                      loadData(3,snum);
                  });
                  var countref=0;
                  $(document).on("pageshow","#msgListPage",function(){
                      //alert("触发 pageshow 事件 - 现在显示页面二");
                      if(countref!=0){//首次加载
                          //alert("触发 pageshow 事件 - 现在显示页面二");
                          loadData(3,0);//重新加载数据
                          $('#moreDiv').show();
                          snum = 0;
                      }
                      countref++;
                  });
                  //var none = true;

                  /*$(window).scroll( function() {
                      *//*alert("滚动条到顶部的垂直高度: "+$(document).scrollTop());
                       alert("页面的文档高度 ："+$(document).height());
                       alert('浏览器的高度：'+$(window).height());*//*
                      var high = $(document).scrollTop()+$(window).height();
                      *//*alert(high);
                      alert($(document).height());*//*
                      if(high>=$(document).height()){
                          //alert('ssssssss');
                          //去动态加载数据
                          snum+=10;
                          if(none){
                              alert(snum);
                              loadData(0,snum);
                          }
                      }
                      *//*console.log("滚动条到顶部的垂直高度: "+$(document).scrollTop());
                       console.log("页面的文档高度 ："+$(document).height());
                       console.log('浏览器的高度：'+$(window).height());*//*

                  });*/
                  loadData(3,0);
              });
              function loadData(num,snum){
                  $.get('/view/getMsgList?openid=<%=openid%>&num='+num+'&snum='+snum+'&random='+Math.random(),function(result,status){//加载数据
                      var count=1;
                      var html='';
                      //alert(result);
                      var msgList = result[0];
                      /*if(msgList.length<3){
                          $('#moreDiv').hide();
                      }*/
                      for(var i=0;i<msgList.length;i++){
                          count +=i;
                          var status;
                          //alert(msgList[i].publicChat);
                          if(msgList[i].publicChat!=0){
                              status = '已公开';
                          }else{
                              status = '未公开';
                          }
                          var content = '';
                          if(msgList[i].msgtype=='image'){
                              content = '[图片]'
                          }else{
                              content = msgList[i].sendcontent
                          }

                          html+="<li><div style='width: 100%'><div style='width: 25%; white-space:pre-wrap; float: left'>提问主题：</div>" +
                                  "<div style='width: 70%; white-space:pre-wrap; float: left' >"+content+"</div>" +
                                  "<div style='width: 25%; white-space:pre-wrap; float: left'>对方名称：</div>" +
                                  "<div style='width: 58%; float: left'>"+msgList[i].nickName+"</div><div  style='width: 12%; float: left; color: #008B00;'>"+status+"</div>" +
                                  "<div style='width: 25%; white-space:pre-wrap; float: left'>对话时间：</div>" +
                                  "<div style='width: 75%; float: left'>"+msgList[i].date+"<div style='float: right'>" +
                                  "<a href='/view/chatDetail?sid="+msgList[i].wcsessionid+"&oid="+result[2]+"&openid="+result[1]+"&ispub="+msgList[i].publicChat+"' style='color: #00B2EE;'>查看详细</a></div></div></div></li>"
                      }
                      if(snum>0){
                          //alert('新增');
                          $("#listview").append( html).listview( "refresh" );
                      }else{
                          //alert('初始化')
                          $("#listview").html( html).listview( "refresh" );
                          //$("#listview").html( '').listview( "refresh" );
                      }

                      //$("#listview").listview( "refresh" );
                      $("#listview").trigger( "updatelayout");
                  });
              }

          </script>
          <!--<div class="orderlistdes">
              <a href="/wcpay/orderlist?openid=<%=openid%>"><h3>查看服务记录</h3></a>
          </div>-->
          <!--<div class="balance" style="color: #00B2EE;">
            聊天记录共&nbsp;&nbsp;条
          </div>-->
          <div style="width: 100%">
          <ol id="listview" data-role="listview" data-inset="true" >

          </ol>
              <div id="moreDiv" style="margin-top: 15px;">
                  <button id="btnMore" data-icon="refresh">
                      显示更多
                  </button>
              </div>

          </div>
      </div>
    </div>
  </body>
</html>